<template>
  <section class='container'>
   <input v-model="q" type="text"/>
   {{ q }}
  </section>
</template>

<script setup>
useHead({title: 'ABOUT'})

import CryptoJS from 'crypto-js';
import { ref } from 'vue'
const appid = '20240813002122517'
const key = 'R1VWv5aTRNehd4bHIDE9'
const salt = new Date().getTime()
const q = ref('hello')
const from = 'en'
const to = 'zh'
// 生成签名
const textToHash = appid + q + salt + key;
const sign = CryptoJS.MD5(textToHash).toString();

try {
  const item = await $fetch(`https://fanyi-api.baidu.com/api/trans/vip/translate?q=${q.value}&from=${from}&to=${to}&appid=${appid}&salt=${salt}&sign=${sign}`, {
  method: 'GET',
  mode: 'no-cors', // 不检查响应头部
  credentials: 'omit', // 不发送凭据
  })
} catch (error) {
}
// const item = await $fetch(`https://fanyi-api.baidu.com/api/trans/vip/translate?q=${q}&from=${from}&to=${to}&appid=${appid}&salt=${salt}&sign=${sign}`)

// const trans_result = item?.trans_result[0]?.dst || ''


</script>

<style scoped >
</style>